<?php
final class User {
	private $user_id;
	private $account;
	private $nickname;
	
  	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->db = $registry->get('db');
		$this->request = $registry->get('request');
		$this->session = $registry->get('session');
		
		if(isset($registry->get('session')->data['user_id'])){
			$this->user_id=$registry->get('session')->data['user_id'];
			
			$this->account=$registry->get('session')->data['account'];
			$this->nickname=$registry->get('session')->data['nickname'];
		} 
	}
		
  	public function login($userdata) {
		
		if ($userdata) {
		   
			$this->user_id=$userdata['user_id'];
	  		return true;
    	} else {
      		return false;
    	}
  	}
  
  	public function logout() {
		unset($this->session->data['$user_id']);
		unset($this->session->data['$account']);
		unset($this->session->data['$nickname']);

		$this->user_id = '';
		$this->account='';
		$this->nickname='';
		
		session_destroy();
  	}
  
  	public function isLogged() {
    	return $this->user_id;
  	}

  	public function getId() {
    	return $this->user_id;
  	}
      
  	public function getAccount() {
		return $this->account;
  	}
  
	public function getNickname() {
		return $this->nickname;
  	}
}
?>